package com.kyp.basic;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class BasicCalcGroupKeyComparator extends WritableComparator {
	protected BasicCalcGroupKeyComparator(){
		super(BasicCalcKey.class, true);
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		BasicCalcKey k1 = (BasicCalcKey)a;
		BasicCalcKey k2 = (BasicCalcKey)b;
		
		int cmp = k1.getGroupColumnKey().compareTo(k2.getGroupColumnKey());
		if (cmp != 0) {
			return cmp;
		}

		return k1.getColumnIndex() == k2.getColumnIndex() ? 0 : (k1
				.getColumnIndex() < k2.getColumnIndex() ? -1 : 1);
	}
}
